﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Acms.Bll;
using Telerik.Web.UI;

public partial class Menus_Default : BaseMenuPage
{
    public override Role.Roles[] AllowedRoles
    {
        get { return new Role.Roles[]{Role.Roles.Developer, Role.Roles.ContentEditor, Role.Roles.ContentViewer}; }
    }

    public override Role.Roles[] EditRoles
    {
        get { return new Role.Roles[]{Role.Roles.Developer}; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!User.HasRole(EditRoles))
            {
                gridMenus.AllowAutomaticInserts = false;
                gridMenus.AllowAutomaticDeletes = false;
                gridMenus.AllowAutomaticUpdates = false;
                GridColumn editCol = gridMenus.Columns.FindByUniqueName("Edit");
                if(editCol!= null)
                    editCol.Display = false;
                GridColumn deleteCol = gridMenus.Columns.FindByUniqueName("Delete");
                if (deleteCol != null)
                    deleteCol.Display = false;
                gridMenus.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;
            }
        }
    }

    protected void dsMenus_SelectData(object sender, Acms.DataControls.SelectEventArgs<Acms.Bll.Menu> e)
    {
        e.SetData(Acms.Bll.Menu.GetAllBySiteId(AcmsContext.SiteId));
    }

    protected void dsMenus_UpdatingData(object sender, Acms.DataControls.UpdatingDataEventArgs<Acms.Bll.Menu> e)
    {
        if (e.Action == Acms.DataControls.UpdateAction.Insert)
        {
            e.Item.SetSiteId(AcmsContext.SiteId);
        }
    }
}
